package com.es.gateway.一砂云.实名认证人工审核版;

import com.es.gateway.sdk.ESGateway;
import com.es.gateway.sdk.app.rpverifyExt.RpverifyExtRequest;
import com.es.gateway.sdk.app.rpverifyExt.UploadIDIMGRequest;
import com.es.gateway.sdk.app.rpverifyExt.UploadIDIMGResponse;
import com.es.gateway.sdk.constant.AlgorithmE;
import com.es.gateway.sdk.entity.GatewayResponse;
import com.es.gateway.sdk.util.B64Util;
import com.es.gateway.sdk.util.CommUtil;
import com.es.gateway.sdk.util.ResourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class EsRPverifyExtTester {
    /**
     * 测试证件上传
     */
    @Test
    public void uploadIDIMGRequestTest() {
        String appCode = "d2808c1338ce01f3e3efdb486f9effb9";
        AlgorithmE algo = AlgorithmE.MD5;
        String key = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhdQdw6uTGz+X4e+/eGpu4dcKrfrjQAe0tTQyn6TuKBobcsUsESkx9jcCeG4cpuxmN8jNeDAZsbTujNLD/aYl2g==";
        ESGateway esGateway = new ESGateway(appCode, algo, key);

        UploadIDIMGRequest uploadIDIMGRequest = new UploadIDIMGRequest();
        uploadIDIMGRequest.setBizId(CommUtil.getCurrentTimeStr());
        byte[] imgBuff = new ResourceUtil().loadResource("cn_idcard.jpeg");
        String imgBase64Str = B64Util.encodeStr(imgBuff);
        uploadIDIMGRequest.setIDImg(imgBase64Str);
        uploadIDIMGRequest.setCountryISOCode("US");
        uploadIDIMGRequest.setIDNumber("102020000000");
        uploadIDIMGRequest.setName("PONY");
        uploadIDIMGRequest.setIDType("passport");

        // 调用通用接口查询余额,文档: https://esandinfo.yuque.com/yv6e1k/aa4qsg/la1w7otq7vg00i1g
        GatewayResponse gatewayResponse = esGateway.sendToGateWay(UploadIDIMGRequest.act, uploadIDIMGRequest.toJsonStr());
        log.info("服务器端返回: {}", gatewayResponse.toJsonStr());
        if (gatewayResponse.getBizContent() != null) {
            log.info("数据验签结果: {}", gatewayResponse.isSignVerifyResult());
            UploadIDIMGResponse response = UploadIDIMGResponse.fromJsonStr(gatewayResponse.getBizContent());
            log.info("业务数据为: {}", response.toJsonStr());
        }
    }


    /**
     * 获取认证Url
     */
    @Test
    public void getVerifyURL() {
        String appCode = "d2808c1338ce01f3e3efdb486f9effb9";
        AlgorithmE algo = AlgorithmE.MD5;
        String key = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhdQdw6uTGz+X4e+/eGpu4dcKrfrjQAe0tTQyn6TuKBobcsUsESkx9jcCeG4cpuxmN8jNeDAZsbTujNLD/aYl2g==";
        ESGateway esGateway = new ESGateway(appCode, algo, key);

        RpverifyExtRequest request = new RpverifyExtRequest();
        request.setEid("20231127194945330_qfeu");

        request.setReturnUrl("");
        request.setNotifyUrl("");
        request.setLivingType("3");
        request.setBizId("123");
        GatewayResponse gatewayResponse = esGateway.sendToGateWay(RpverifyExtRequest.act, request.toJsonStr());
        log.info("服务器端返回: {}", gatewayResponse.toJsonStr());
        if (gatewayResponse.getBizContent() != null) {
            log.info("数据验签结果: {}", gatewayResponse.isSignVerifyResult());
            UploadIDIMGResponse response = UploadIDIMGResponse.fromJsonStr(gatewayResponse.getBizContent());
            log.info("业务数据为: {}", response.toJsonStr());
        }
    }
}
